home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / mono.asm < prev    next >
Encoding:
Assembly Source File  |  1999-07-04  |  8.8 KB  |  493 lines

  1. ; Mono
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.1
  6.  
  7.     MACHINE    68020
  8.  
  9.         INCDIR    Include:
  10.  
  11.     INCLUDE exec/types.i
  12.     INCLUDE    exec/memory.i
  13.     INCLUDE    exec/exec_lib.i
  14.     INCLUDE    utility/tagitem.i
  15.     INCLUDE    intuition/intuition.i
  16.     INCLUDE    intuition/intuition_lib.i
  17.     INCLUDE    intuition/screens.i
  18.     INCLUDE    graphics/graphics_lib.i
  19.     INCLUDE graphics/modeid.i
  20.     INCLUDE    graphics/rastport.i
  21.     INCLUDE    dos/dos.i
  22.     INCLUDE    dos/dos_lib.i
  23.     INCLUDE    libraries/asl.i
  24.     INCLUDE    libraries/asl_lib.i
  25.     INCLUDE    macros.i
  26.  
  27. ;*** Handler structure
  28.  
  29.  STRUCTURE vxd_handler,0
  30.   LONG intuibase
  31.   LONG graphbase
  32.   LONG dosbase
  33.   LONG aslbase
  34.   LONG myscr
  35.   LONG mywin
  36.   LONG planes
  37.   WORD xsize
  38.   WORD ysize
  39.   LONG palette
  40.   LONG palettemono
  41.   LONG emuscr
  42.   LONG cmpbuffer
  43.   LONG scrmodereq
  44.   LONG screendim
  45.   WORD bytesperrow
  46.   WORD skip
  47.  LABEL    vxd_handler_SIZEOF
  48.  
  49. JSRLIB    MACRO
  50.     jsr    _LVO\1(a6)
  51.     ENDM
  52.  
  53. ;*** Let's begin
  54.  
  55.     moveq.l    #0,d0
  56.     rts
  57.  
  58.     dc.b "FLAMINGOXVD"
  59.     dc.b "1"
  60.  
  61.     dc.l Name
  62.     dc.l Author
  63.     dc.w 1
  64.     dc.w 1
  65.  
  66.     dc.l drv_Init
  67.     dc.l drv_Done
  68.     dc.l drv_Configure
  69.     dc.l drv_OpenScreen
  70.     dc.l drv_CloseScreen
  71.     dc.l drv_Refresh
  72.  
  73. Name:    dc.b    "Mono (B&W) External Video Driver",0
  74. Author:    dc.b    "Álmos Rajnai",0
  75.  
  76.     EVEN
  77.  
  78. ;*** Functions
  79.  
  80. drv_Init:
  81.     movem.l    a0-a1,-(sp)    ;Saving infos
  82.     move.l  4.w,a6        ;Alloc memory for handler
  83.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  84.     move.l    #vxd_handler_SIZEOF,d0
  85.     JSRLIB    AllocVec
  86.     movem.l    (sp)+,a0-a1    ;Recover infos
  87.         cmp.l    #0,d0
  88.     beq.b    .1        ;No mem
  89.     movea.l    d0,a2
  90.         move.l    (a0),graphbase(a2)    ;Saving graphics.library base
  91.         move.l    4(a0),dosbase(a2)    ;Saving dos.library base
  92.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  93.         move.l    16(a0),aslbase(a2)    ;Saving asl.library base
  94.         movem.l    d0,-(sp)
  95.  
  96.     move.l    dosbase(a2),a6        ;Reading config file
  97.     move.l    #configfile,d1        ;Config file is pretty simple:
  98.     move.l    #MODE_OLDFILE,d2    ;only a screenmode number
  99.     JSRLIB    Open
  100.     tst.l    d0
  101.     beq.b    .2            ;Failed open
  102.     move.l    d0,d1
  103.     move.l    (sp),a0
  104.     lea    screendim(a0),a0
  105.     move.l    a0,d2
  106.     moveq.l    #4,d3
  107.     movem.l    d0,-(sp)
  108.     JSRLIB    Read            ;Reading the 4 bytes
  109.     cmp.l    #4,d0
  110.     beq.b    .3
  111.     move.l    (sp),a0            ;Failed: set 0 instead garbage
  112.     move.l    #0,screendim(a0)
  113.  
  114. .3    movem.l    (sp)+,d1
  115.     JSRLIB    Close
  116.  
  117. .2    movem.l    (sp)+,d0
  118. .1    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  119.     rts                ;Result in D0 available for now
  120.  
  121. drv_Done:
  122.     movea.l    a0,a1
  123.     cmpa.l    #0,a1
  124.     beq.b    .1
  125.     movem.l    4.w,a6
  126.     JSRLIB    FreeVec        ;Deallocate handler
  127. .1
  128.     rts
  129.  
  130. drv_Configure:            ;Configure
  131.                 ;A simple screenmode requester appears
  132.     movem.l    a0,-(sp)
  133.     move.l    screendim(a0),displayid
  134.     move.l    #ASL_ScreenModeRequest,d0    
  135.     move.l    aslbase(a0),a6
  136.     lea    asltags,a0
  137.     JSRLIB    AllocAslRequest
  138.     move.l    (sp),a0
  139.     move.l    d0,scrmodereq(a0)
  140.     tst.l    d0
  141.     bne.b    config2
  142.     move.l    intuibase(a0),a6
  143.     JSRLIB    DisplayBeep
  144.     lea    4(sp),sp
  145.     rts
  146.  
  147. config2:
  148.     move.l    d0,a0
  149.     suba.l    a1,a1
  150.     JSRLIB    AslRequest
  151.     tst.l    d0
  152.     beq.b    .1
  153.  
  154.     move.l    (sp),a1
  155.     move.l    scrmodereq(a1),a0
  156.     move.l    sm_DisplayID(a0),screendim(a1)
  157.  
  158.     move.l    dosbase(a1),a6        ;Writing config file
  159.     move.l    #configfile,d1        ;Config file is pretty simple:
  160.     move.l    #MODE_NEWFILE,d2    ;only a screenmode number
  161.     JSRLIB    Open
  162.     tst.l    d0
  163.     beq.b    .1            ;Failed open
  164.     move.l    d0,d1
  165.     move.l    (sp),a0
  166.     lea    screendim(a0),a0
  167.     move.l    a0,d2
  168.     moveq.l    #4,d3
  169.     movem.l    d0,-(sp)
  170.     JSRLIB    Write            ;Writing the 4 bytes
  171.  
  172.     movem.l    (sp)+,d1        ;We don't care too much on
  173.     JSRLIB    Close            ;success...
  174.  
  175. .1    movem.l    (sp)+,a0
  176.     move.l    aslbase(a0),a6
  177.     move.l    scrmodereq(a0),a0
  178.     JSRLIB    FreeAslRequest
  179.     rts
  180.  
  181. drv_OpenScreen:
  182.     movea.l a0,a5
  183.     move.w    (a1)+,xsize(a5)
  184.     move.w    (a1)+,ysize(a5)
  185.     move.l    (a1)+,palette(a5)
  186.     move.l    screendim(a5),screenmode    ;screenmode from init
  187.  
  188.     moveq.l    #0,d0
  189.     move.l    d0,d1
  190.     move.w    xsize(a5),d0
  191.     move.w    ysize(a5),d1
  192.     mulu.w    d1,d0
  193.     move.l    d0,d7    
  194.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  195.     move.l    4.w,a6
  196.     JSRLIB    AllocVec
  197.     move.l    d0,emuscr(a5)        ;allocating emulator screen
  198.     beq.w    .1
  199.  
  200.     move.l    d7,d0
  201.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  202.     JSRLIB    AllocVec
  203.     move.l    d0,cmpbuffer(a5)    ;allocating cmp buffer
  204.     beq.w    .1
  205.  
  206.     move.l    #MEMF_PUBLIC,d1
  207.     move.l    #8*128,d0
  208.     JSRLIB    AllocVec
  209.     move.l    d0,palettemono(a5)    ;Convert palette to 1 bit
  210.     beq.w    .1
  211.     movea.l    d0,a0
  212.     move.l    #128-1,d2
  213.         move.l    palette(a5),a1
  214.     moveq.w    #0,d0
  215. .2    moveq.w    #0,d1
  216.     move.b    (a1)+,d1        ;Sum of R,G,B
  217.     move.b    (a1)+,d0
  218.     add.w    d0,d1
  219.     move.b    (a1)+,d0
  220.     add.w    d0,d1
  221.     cmp.w    #255,d1            ;Less than a third?
  222.     blt.b    .less
  223.     move.b    #$ff,d3
  224.     bra.b    .cont
  225. .less    move.b    #$0,d3
  226. .cont    move.b    d3,d4
  227.     and.b    #1<<0,d4
  228.     move.b    d4,128*7(a0)
  229.     move.b    d3,d4
  230.     and.b    #1<<1,d4
  231.     move.b    d4,128*6(a0)
  232.     move.b    d3,d4
  233.     and.b    #1<<2,d4
  234.     move.b    d4,128*5(a0)
  235.     move.b    d3,d4
  236.     and.b    #1<<3,d4
  237.     move.b    d4,128*4(a0)
  238.     move.b    d3,d4
  239.     and.b    #1<<4,d4
  240.     move.b    d4,128*3(a0)
  241.     move.b    d3,d4
  242.     and.b    #1<<5,d4
  243.     move.b    d4,128*2(a0)
  244.     move.b    d3,d4
  245.     and.b    #1<<6,d4
  246.     move.b    d4,128*1(a0)
  247.     move.b    d3,d4
  248.     and.b    #1<<7,d4
  249.     move.b    d4,(a0)+
  250.     dbf    d2,.2
  251.     move.w    xsize(a5),width+2
  252.     move.w    ysize(a5),height+2
  253.  
  254.         suba.l    a0,a0            ;No newscreen stuct
  255.         lea    scrtags,a1
  256.     movea.l    intuibase(a5),a6
  257.     JSRLIB    OpenScreenTagList
  258.     move.l    d0,myscr(a5)
  259.     beq.w    .1
  260.     move.l    d0,wscr
  261.     move.l    d0,a0
  262.     lea    sc_RastPort(a0),a0
  263.     movea.l    rp_BitMap(a0),a0
  264.     move.l    #BMA_FLAGS,d1
  265.     movea.l    graphbase(a5),a6
  266.     JSRLIB    GetBitMapAttr
  267.     and.l    #BMF_STANDARD,d0
  268.     cmp.l    #BMF_STANDARD,d0
  269.     beq.b    .3
  270.     movea.l    intuibase(a5),a6
  271.     move.l    myscr(a5),a0
  272.     JSRLIB    CloseScreen
  273.     moveq.l    #0,d0
  274.     move.l    d0,myscr(a5)
  275.     bra.b    .1
  276.  
  277. .3    move.w    xsize(a5),wwidth+2
  278.     move.w    ysize(a5),wheight+2
  279.     suba.l    a0,a0
  280.     lea    wintags,a1
  281.     movea.l    intuibase(a5),a6
  282.     JSRLIB    OpenWindowTagList
  283.     move.l    d0,mywin(a5)
  284.     beq.b    .1
  285.     movea.l    d0,a1
  286.     move.l  wd_RPort(a1),a0
  287.     move.l    rp_BitMap(a0),a0
  288.     move.l    bm_Planes(a0),planes(a5)
  289.     move.w    xsize(a5),d0
  290.     lsr.w    #3,d0
  291.     move.w    d0,d1
  292.     move.w    d1,bytesperrow(a5)
  293.     move.w    bm_BytesPerRow(a0),d1
  294.     sub.w    d0,d1
  295.     move.w    d1,skip(a5)
  296.     move.l  wd_UserPort(a1),d0    ;IDCMP port
  297.     move.l    emuscr(a5),d2        ;chunky buffer
  298.  
  299. .1    move.l    #err_noscr,d1
  300.     moveq.l    #0,d3            ;No modulo for the chunky screen
  301.     rts
  302.  
  303. drv_CloseScreen:
  304.     move.l    a0,a5
  305.     move.l    intuibase(a5),a6
  306.     move.l    mywin(a5),a0
  307.     cmpa.l    #0,a0
  308.     beq.b    .1
  309.     JSRLIB    CloseWindow
  310.  
  311. .1    move.l    myscr(a5),a0
  312.     cmpa.l    #0,a0
  313.     beq.b    .2
  314.     JSRLIB    CloseScreen
  315.  
  316. .2    movea.l    palettemono(a5),a1
  317.         cmpa.l    #0,a1
  318.     beq.b    .3
  319.     move.l    4.w,a6
  320.     JSRLIB    FreeVec        ;Deallocate translated palette
  321.  
  322. .3    movea.l    emuscr(a5),a1
  323.         cmpa.l    #0,a1
  324.     beq.b    .4
  325.     move.l    4.w,a6
  326.     JSRLIB    FreeVec        ;Deallocate chunky buffer
  327. .4
  328.     movea.l    cmpbuffer(a5),a1
  329.         cmpa.l    #0,a1
  330.     beq.b    .5
  331.     move.l    4.w,a6
  332.     JSRLIB    FreeVec        ;Deallocate delta buffer
  333. .5
  334.     moveq.l    #0,d0
  335.     move.l    d0,emuscr(a5)    ;They were already freed
  336.     move.l    d0,cmpbuffer(a5)
  337.     move.l    d0,palettemono(a5)
  338.     move.l    d0,myscr(a5)
  339.     move.l    d0,mywin(a5)
  340.  
  341.     rts
  342.  
  343. drv_Refresh:
  344.  
  345.     move.w    ysize(a0),d0
  346.     subq.w    #1,d0
  347.     movea.l    emuscr(a0),a1
  348.     movem.l    a1,-(sp)        ;storing chunky buffer
  349.     movea.l    palettemono(a0),a4
  350.     movea.l    planes(a0),a3
  351.     moveq.l    #0,d3
  352.     move.l    d3,d5
  353.     move.l    d3,d7
  354.     move.l    d3,d4
  355.     move.w    skip(a0),d7
  356.     move.w    bytesperrow(a0),d5
  357.     move.w    xsize(a0),d4
  358.     movea.l    cmpbuffer(a0),a0
  359.  
  360. .difcyc2
  361.     move.w    d4,d6
  362.     lsr.w    #2,d6
  363.     subq.w    #1,d6
  364.     movea.l    a1,a6
  365.     movea.l    a0,a5
  366. .difcyc    cmp.l    (a6)+,(a5)+
  367.     beq.b    .nodifference
  368.  
  369.     move.w    d5,d6    
  370.     subq.l    #1,d6
  371. .cyc    moveq.b    #0,d2
  372.     movea.l    a4,a2
  373.  
  374.     move.b    (a1)+,d3
  375.     move.b    d3,(a0)+
  376.     or.b    (a2,d3.w),d2
  377.     adda.l    #128,a2
  378.  
  379.     move.b    (a1)+,d3
  380.     move.b    d3,(a0)+
  381.     or.b    (a2,d3.w),d2
  382.     adda.l    #128,a2
  383.  
  384.     move.b    (a1)+,d3
  385.     move.b    d3,(a0)+
  386.     or.b    (a2,d3.w),d2
  387.     adda.l    #128,a2
  388.  
  389.     move.b    (a1)+,d3
  390.     move.b    d3,(a0)+
  391.     or.b    (a2,d3.w),d2
  392.     adda.l    #128,a2
  393.  
  394.     move.b    (a1)+,d3
  395.     move.b    d3,(a0)+
  396.     or.b    (a2,d3.w),d2
  397.     adda.l    #128,a2
  398.  
  399.     move.b    (a1)+,d3
  400.     move.b    d3,(a0)+
  401.     or.b    (a2,d3.w),d2
  402.     adda.l    #128,a2
  403.  
  404.     move.b    (a1)+,d3
  405.     move.b    d3,(a0)+
  406.     or.b    (a2,d3.w),d2
  407.     adda.l    #128,a2
  408.  
  409.     move.b    (a1)+,d3
  410.     move.b    d3,(a0)+
  411.     or.b    (a2,d3.w),d2
  412.  
  413.     move.b    d2,(a3)+
  414.     dbf    d6,.cyc
  415.     bra.b    .cont
  416.  
  417. .nodifference
  418.     dbf    d6,.difcyc
  419.     adda.l    d5,a3
  420.     adda.l    d4,a1
  421.     adda.l    d4,a0
  422. .cont    adda.l    d7,a3
  423.     dbf    d0,.difcyc2
  424.  
  425.     movem.l    (sp)+,d0    ;giving back chunky buffer
  426.     
  427.         rts
  428.  
  429. ;*** Constants
  430.  
  431. scrtags:
  432.     dc.l    SA_Width
  433. width:    dc.l    0
  434.     dc.l    SA_Height
  435. height:    dc.l    0
  436.     dc.l    SA_Depth,1
  437.     dc.l    SA_Colors32,mypalette
  438.     dc.l    SA_Title,scrtitle
  439.     dc.l    SA_ShowTitle,FALSE
  440.     dc.l    SA_DisplayID
  441. screenmode:
  442.     dc.l    0
  443.     dc.l    SA_Interleaved,TRUE
  444.     dc.l    SA_Type,CUSTOMSCREEN
  445.     dc.l    SA_AutoScroll,TRUE
  446.     dc.l    SA_Overscan,OSCAN_STANDARD
  447.     dc.l    SA_Quiet,TRUE
  448.     dc.l    TAG_DONE
  449.  
  450. wintags:
  451.     dc.l    WA_Left,0
  452.     dc.l    WA_Top,0
  453.     dc.l    WA_Width
  454. wwidth:    dc.l    0
  455.     dc.l    WA_Height
  456. wheight:    dc.l    0
  457.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  458.     dc.l    WA_Title,0
  459.     dc.l    WA_Backdrop,TRUE
  460.     dc.l    WA_RMBTrap,TRUE
  461.     dc.l    WA_Borderless,TRUE
  462.     dc.l    WA_NoCareRefresh,TRUE
  463.     dc.l    WA_CustomScreen
  464. wscr:    dc.l    0
  465.     dc.l    WA_SimpleRefresh,TRUE
  466.     dc.l    WA_Activate,TRUE
  467.     dc.l    TAG_DONE
  468.  
  469. mypalette:
  470.     dc.w    2,0
  471.     dc.l    0,0,0,$ff000000,$ff000000,$ff000000,0,0,0,0
  472.  
  473. asltags:
  474.     dc.l    ASLSM_TitleText,configwintxt
  475.     dc.l    ASLSM_InitialDisplayID
  476. displayid:
  477.     dc.l    0
  478.     dc.l    TAG_DONE
  479.  
  480.  
  481. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  482.  
  483. configwintxt:    dc.b    'Choose desired screenmode',0
  484.  
  485. configfile:    dc.b    'mono.cfg',0
  486.  
  487. ;*** Errors
  488.  
  489. err_nomem:
  490.     dc.b    'Run out of memory',0
  491. err_noscr:
  492.     dc.b    'Cannot open screen',0
  493.